'use strict';
const dayjs = require("dayjs");
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { STRING, INTEGER, DATE, TINYINT, TEXT } = app.Sequelize;
    return app.model.define(
        'TravelCustom',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            user_id: INTEGER,
            name: STRING(255),
            phone: STRING(11),
            travel_date: DATE,
            destination: STRING(255),
            adult_count: INTEGER,
            child_count: INTEGER,
            budget: STRING(255),
            handler: STRING(255),
            status: {type: TINYINT, defaultValue: 0}, // 0:待处理 1:处理中 2:已完成 3:已取消
            remark: TEXT,
            handler_remark: TEXT,
            plan_file_path: TEXT,
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'travel_custom',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );

    TravelCustom.associate = function() {
        app.model.Business.TravelCustom.belongsTo(app.model.Business.User, {as: 'user', foreignKey: 'user_id'});
        app.model.Business.TravelCustom.belongsTo(app.model.System.SystemUser, {as: 'handler', foreignKey: 'handler_id'});
    }
    
    return TravelCustom;
}; 